//
//  NXTabBarController.m
//  NXMainFrameObject
//
//  Created by 宋钢强 on 2018/4/16.
//  Copyright © 2018年 NiuTan. All rights reserved.
//

#import "NXTabBarController.h"
#import "NXTabBar.h"

@interface NXTabBarController ()<NXTabBarDelegate>

@property (nonatomic,strong)UITabBarItem *item;

@end


@implementation NXTabBarController
- (void)viewDidLoad {
    [super viewDidLoad];
        

}

- (void)setStyle:(TabBarStyle)style {
    _style = style;
    if (self.style == TabBarStyleCenterIcon) {
        //更换系统自带的tabbar
        NXTabBar *tabbar = [[NXTabBar alloc]init];
        tabbar.tabbarDelegate = self;
        [self setValue:tabbar forKey:@"tabBar"];
    }
}

#pragma mark - 添加子控制器
-(void)addChildViewController:(UIViewController *)childVc  title:(NSString *)title image:(NSString *)image selImage:(NSString *)selImage {
    static NSInteger index = 0;
    //设置子控制器的TabBarButton属性
    childVc.tabBarItem.title = title;
    childVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.tag = index;
    index++;
    //让子控制器包装一个导航控制器
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:childVc];
    [self addChildViewController:nav];
}

//+ (void)initialize
//{
//    //设置未选中的TabBarItem的字体颜色、大小
//    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
//    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
//    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
//    //设置选中了的TabBarItem的字体颜色、大小
//    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
//    selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
//    selectedAttrs[NSForegroundColorAttributeName] =  [UIColor orangeColor];
//    UITabBarItem *item = [UITabBarItem appearance];
//    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
//    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
//}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    NSLog(@"点击的item:%ld title:%@", item.tag, item.title);
}

#pragma mark - 加号按钮响应方法
-(void)tabBarDidClickPlusButton:(NXTabBar *)tabBar {
    if ([self.tabBarDelegate respondsToSelector:@selector(tabBarDidClickNXTabBar:)]) {
        [self.tabBarDelegate tabBarDidClickNXTabBar:self];
    }
}

//设置按钮方法
-(void)setAction:(UIImageView *)imageView action:(SEL)action{
    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:action];
    imageView.userInteractionEnabled = YES;
    [imageView addGestureRecognizer:gesture];
}

- (void)setNorTitleColor:(UIColor *)norTitleColor {
    _norTitleColor = norTitleColor;
    
    //设置未选中的TabBarItem的字体颜色、大小
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = norTitleColor;
    UITabBarItem *item = [UITabBarItem appearance];
    self.item = item;
    [self.item setTitleTextAttributes:attrs forState:UIControlStateNormal];
}


- (void)setSelTitleColor:(UIColor *)selTitleColor {
    _selTitleColor = selTitleColor;
    //设置选中了的TabBarItem的字体颜色、大小
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    selectedAttrs[NSForegroundColorAttributeName] =  selTitleColor;
    UITabBarItem *item = [UITabBarItem appearance];
    self.item = item;
    [self.item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}







@end

